<include file="Public/head" title="编辑地址"/>
<include file="Public/back_head"/>
<div class="main">
    <div class="add_url">
        <form id="dataForm">
        	<input type="hidden" name="info[id]" value="{$data.id}"/>
        	<input type="hidden" name="info[user_id]" value="{:$data['user_id']?$data['user_id']:$user['id']}"/>
            <div class="top">
                <label for=""><span>收货人</span><input type="text" name="info[name]" placeholder="请输入您的姓名" value="{$data.name}"></label>
                <label for="">
                    <span>手机号</span><input type="tel" name="info[phone]" placeholder="请输入您的手机号" maxlength="11" value="{$data.phone}" id="tel">
                </label>
                <label for="">
                    <span>所在地区</span>
                    <input type="text" placeholder="请选择" name="info[area]"  class="liubai" id="city_select" value="{$data.area}" readonly>
                    <i class="iconfont icon-zuoyoujiantou2"></i>
                </label>
                <label for="">
                    <textarea name="info[address]" class="city_detailed" cols="30" rows="10" placeholder="请填写详细街道楼牌号地址">{$data.address}</textarea>
                </label>
            </div>
            <div class="setting">
                <span>设为默认</span>
                <i class="iconfont icon-Switch1 {:$data['is_default'] == '2'?'hide':''}"></i>
                <i class="iconfont icon-Switch2 {:$data['is_default'] != '2'?'hide':''}"></i>
                <input id="is_default" type="hidden" name="info[is_default]" value="{$data.is_default|default='1'}"/>
            </div>
            <button onclick="save();return false;">保存并使用</button>
        </form>
    </div>
</div>
<link rel="stylesheet" href="__PUBLIC__/home/css/weui2.css">
<script type="text/javascript" src="__PUBLIC__/home/js/zepto.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/picker.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/picker-city.js"></script>
<script type="text/javascript">
$(function () {
    $("#city_select").cityPicker({
        title: "选择省市县"
    });
    //验证手机号
    $('#tel').focus(function () {

    }).blur(function() {
        var str=$(this).val();
        if(!(/^1[7|3|4|5|8][0-9]\d{8}$/.test(str))){
            layer.msg("手机号格式输入有误<br>请重新输入",{time:1500});
        }
    });
    $(".city_detailed").change(function(){
        if($("input").val()!=""){
            $("button").removeAttr("disabled");
        }
    })
    $('.icon-Switch1').click(function () {
        $(this).hide();
        $('.icon-Switch2').show();
        $("#is_default").val(2);
    });
    $('.icon-Switch2').click(function () {
        $(this).hide();
        $('.icon-Switch1').show();
        $("#is_default").val(1);
    })
})
function save(){
	$.post("{:U('address_save')}",$('#dataForm').serializeArray(),function(data){
		layer.msg(data.info);
		data.status == '1' && setTimeout("location.href='"+data.url+"'",1000);
	});
}
</script>
<include file="Public/foot"/>